terminalwork = new Vue({
	el: "#terminalwork",
	data: {
		isShowList:false,
		userInfo:'', // 用户信息
		
		stationList:[], // 电站列表
		
		terminalKeyword:'', // 关键字
		currentPage:1, // 当前页
		terminalworkList:[], // 定期工作列表
		
	},
	components:{
	},
	mounted: function() {
		// 获取用户信息
		this.userInfo = JSON.parse(localStorage.getItem('neiosUser'))
		localStorage.setItem("todoWork",'')
		
		let _this = this
		// 获取人员信息
		let userInfo = JSON.parse(localStorage.getItem('neiosUser'))
		if (userInfo.roles.indexOf('NEIOS_STATION') > -1) {
			$('.neios-station-name').text(localStorage.getItem('neiosStationName'))
			if (userInfo.stationNewCodes.length > 1) {
				$('.neios-station-btn').show()
				for (let a = 0; a < userInfo.stationNewCodes.length; a++) {
					let item = {
						name : userInfo.stationNewNames[a],
						code : userInfo.stationNewCodes[a]
					}
					_this.stationList.push(item)
				}
			}
		}
		// 获取列表
		this.queryTerminalList(this.currentPage);  
		
	},
	methods: {
		// 切换场站
		changeStation (item) {
			$('.neios-station-dialog-box').hide()
			localStorage.setItem('neiosStationName',item.name)
			localStorage.setItem('neiosStationCode',item.code)
			$('.neios-station-name').text(item.name)
			this.currentPage = 1
			this.queryTerminalList(1)
		},
		// 查询列表
		queryTerminalList (current) {
			let url = '/app/common/querySysNoticeByKeyWord'
			let _this = this
			let param = {
				pageIndex:current,
				pageSize: 10,
				keyWord:this.terminalKeyword,
				newAreaCode:this.userInfo.companyNewCode,
				newStationCode:localStorage.getItem('neiosStationCode'),
			}
			mui.neiosRequst.httpRequst(url, param,
				function(data) {
					if (data.code == '0') {
						_this.isShowList = true 
						if(_this.currentPage == 1){
							mui('#terminalworkList').pullRefresh().enablePullupToRefresh();
							mui('#terminalworkList').pullRefresh().endPullupToRefresh();
							_this.terminalworkList = data.data.records
						} else{
							mui('#terminalworkList').pullRefresh().endPullupToRefresh();
							_this.terminalworkList = _this.terminalworkList.concat(data.data.records)
						}
						if(data.data.current >= data.data.pages){
							console.log("====================禁用====================") 
							mui('#terminalworkList').pullRefresh().disablePullupToRefresh();
							mui('#terminalworkList').pullRefresh().endPullupToRefresh(true);
						}
					} else {
						_this.terminalworkList = []
						mui.toast('查询列表失败，请稍后重试！')  
					}
				},
				function() {
					_this.terminalworkList = []
					mui.toast('查询列表失败，请稍后重试！')
				}
			);
		},
		// 关键字搜索
		terminalKeywordChange () {
			this.currentPage = 1
			this.queryTerminalList(1)
			this.isShowList = false
		},
		
	}
}); 
$('.neios-station-btn').click(function(){
	let userInfo = JSON.parse(localStorage.getItem('neiosUser'))
	$('.neios-station-dialog-item').removeClass('on')
	let stationDom = $('.neios-station-dialog-item')
	for (let a = 0; a < userInfo.stationNewCodes.length; a++) {
		if (userInfo.stationNewCodes[a] == localStorage.getItem('neiosStationCode')) {
			$(stationDom[a]).addClass('on')
		}
	}
	$('.neios-station-dialog-box').show()
})
mui.init({
	pullRefresh: {
		container: "#terminalworkList", //待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
		down: { //下拉刷新
			style: 'circle',
			height: 50, //可选,默认50.触发下拉刷新拖动距离,
			auto: false, //可选,默认false.首次加载自动下拉刷新一次
			contentdown: "下拉可以刷新", //可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
			contentover: "释放立即刷新", //可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
			contentrefresh: "正在刷新...", //可选，正在刷新状态时，下拉刷新控件上显示的标题内容
			callback: async function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				terminalwork.currentPage = 1;
				terminalwork.queryTerminalList(1);
				////没有更多内容了，endPulldown 传入true， 不再执行下拉刷新
				mui('#terminalworkList').pullRefresh().endPulldownToRefresh();
				mui('#terminalworkList').pullRefresh().enablePullupToRefresh();
				mui('#terminalworkList').pullRefresh().endPullupToRefresh(true); 
			}
		},
		up: { //上拉加载
			height: 50, //可选.默认50.触发上拉加载拖动距离
			auto: false, //可选,默认false.自动上拉加载一次
			contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
			contentnomore: '没有更多数据了', //可选，请求完毕若没有更多数据时显示的提醒内容；
			callback: async function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				terminalwork.currentPage = terminalwork.currentPage*1 + 1;
				terminalwork.queryTerminalList(terminalwork.currentPage);
			}
		}
	},
});
mui.plusReady(function () {
	window.addEventListener('isRefresh',function(){
		window.location.reload()
	})
})
mui('.mui-input-clear')[0].addEventListener('focus',function(){
	mui(".mui-icon-clear")[0].addEventListener('tap',function(){
		terminalwork.terminalKeyword = ''
		terminalwork.queryTerminalList(1);
	})
})